package com.leihao.product.controller;

import com.github.pagehelper.PageInfo;
import com.leihao.common.core.domain.R;
import com.leihao.product.domian.*;
import com.leihao.product.domian.listRequest.BrandListRequest;
import com.leihao.product.service.ProductBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productBrand")
@Api(tags = "商品品牌管理")
public class ProductBrandController {

    @Autowired
    private ProductBrandService productBrandService;

    /**
     * 查询所有商品品牌
     *
     * @param brandListRequest
     * @return
     */
    @PostMapping("/findList")
    @ApiOperation(value = "查询所有商品品牌")
    public R<PageInfo<ProductBrand>> findList(@Validated @RequestBody BrandListRequest brandListRequest) {
        PageInfo<ProductBrand> firstList = productBrandService.findList(brandListRequest);
        return R.ok(firstList);
    }

    /**
     * 根据编号查询商品品牌信息
     *
     * @param productBrandId
     * @return
     */
    @GetMapping("/findById/{productBrandId}")
    @ApiOperation(value = "根据编号查询商品分类信息")
    public R<ProductBrand> findById(@PathVariable Integer productBrandId) {
        ProductBrand productBrand = productBrandService.findById(productBrandId);
        return R.ok(productBrand);
    }

    /**
     * 查询所有品牌
     *
     * @param
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有品牌")
    public R<List<ProductBrand>> findAll() {
        List<ProductBrand> list = productBrandService.findAll();
        return R.ok(list);
    }

    /**
     * 逻辑删除
     *
     * @param productBrandId
     * @return
     */
    @DeleteMapping("/delete/{productBrandId}")
    @ApiOperation(value = "逻辑删除")
    @ApiImplicitParam(name = "productBrandId", value = "主键ID", required = true, dataType = "Integer")
    public R delete(@PathVariable Integer productBrandId) {
        productBrandService.delete(productBrandId);
        return R.ok(null, "删除成功");
    }

    /**
     * 修改商品品牌
     *
     * @param productBrand
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改商品品牌")
    public R update(@RequestBody ProductBrand productBrand) {
        productBrandService.update(productBrand);
        return R.ok(null, "修改成功");
    }

    /**
     * 添加商品品牌
     *
     * @param productBrand
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加商品品牌")
    public R add(@Validated @RequestBody ProductBrand productBrand) {
        productBrandService.add(productBrand);
        return R.ok(null, "添加成功");
    }


}
